package com.study.houserent.view;

import com.study.houserent.domain.House;
import com.study.houserent.service.HouseService;
import com.study.houserent.utils.Utility;

/**
 * 1. 显示界面
 * 2. 接受用户输入
 * 3. 调用 HouseService 完成对房屋信息的操作
 */
public class HouseView {
    private boolean loop = true;
    private char key = ' ';
    private HouseService houseService = new HouseService(10);

    // 接收输入, 创建 House 对象, 调用 add 方法
    public void addHouse() {
        System.out.println("=====添加房屋=====");
        System.out.println("姓名");
        String name = Utility.readString(8);
        System.out.println("电话");
        String phone = Utility.readString(12);
        System.out.println("地址");
        String address = Utility.readString(16);
        System.out.println("月租");
        int rent = Utility.readInt();
        System.out.println("状态");
        String state = Utility.readString(3);
        new House(0, name, phone, address, rent, state);
    }

    // 显示房屋列表
    public void listHouses() {
        System.out.println("=====房屋列表=====");
        System.out.println("编号\t\t房主\t\t电话\t\t地址\t\t月租\t\t状态(已出租/未出租)");
        House[] houses = houseService.list();
        for (int i = 0; i < houses.length; i++) {
            if (houses[i] == null) {
                break;
            }
            System.out.println(houses[i]);
        }
        System.out.println("=====房屋列表显示完毕====");

    }
    // 显示主菜单
    public void mainMenu() {
        do {
            System.out.println("======房屋出租系统菜单======");
            System.out.println("\t\t1 新增房源");
            System.out.println("\t\t2 查找房屋");
            System.out.println("\t\t3 删除房屋信息");
            System.out.println("\t\t4 修改房屋信息");
            System.out.println("\t\t5 显示房屋信息");
            System.out.println("\t\t6 退出");
            System.out.println("请输入你的选择(1-6)");

            key = Utility.readChar();
            switch (key) {
                case '1':
                    System.out.println("新增");
                    break;
                case '2':
                    System.out.println("查找");
                    break;
                case '3':
                    System.out.println("删除");
                    break;
                case '4':
                    System.out.println("修改");
                    break;
                case '5':
                    listHouses();
                    break;
                case '6':
                    System.out.println("退出");
                    loop = false;
                    break;
            }
        } while (loop);
    }
}
